package com.woniuxy.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.nimbusds.jose.JOSEException;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import com.woniuxy.util.ResponseData;
import com.woniuxy.util.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：CuiYC
 * @description：
 * @date ：Created in 2025/3/27 9:32
 * @modified By：
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
@Slf4j
public class UserController {

    private UserService userService;
    @PostMapping("/login")
    public ResponseData<?> login(@RequestBody User user){
        if(StrUtil.isBlank(user.getAccount()) || StrUtil.isBlank(user.getPassword())){
            return ResponseData.fail(ResponseEnum.LOGIN_ERROR);
        }
        try {
            return userService.login(user);
        } catch (Exception e) {
            log.error("登录校验");
            throw new RuntimeException(e);
        }
    }
}
